package main.java.indi.zyj.hot100;

import main.java.indi.zyj.hot100.base.TreeNode;

import java.util.Deque;
import java.util.LinkedList;

public class _38_isValidBST {

    public boolean isValidBST(TreeNode root) {

        Deque<TreeNode> stack = new LinkedList<>();
        double pre = -Double.MAX_VALUE;

        while (root != null || !stack.isEmpty()) {
            while (root != null) {
                stack.push(root);
                root = root.left;
            }
            TreeNode node = stack.pop();
            if (node.val <= pre) {
                return false;
            }
            pre = node.val;
            root = node.right;
        }

        return true;
    }

}
